package com.study.sbsummary.config.swagger;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
	@Value("${swagger.enable}")
	private boolean enable;
	@Bean
	public Docket createRestApi() {
		// http://localhost:8080/doc.html
		ApiInfo apiInfo = new ApiInfoBuilder()
				.title("truely-plog")
				.description("truely-plog")
				.version("0.1") //版本
				.build();

		return new Docket(DocumentationType.SWAGGER_2)
				.enable(enable) //swagger版本
				.pathMapping("/")
				.select()
				//扫描那些controller
				.apis(RequestHandlerSelectors.basePackage("com.truely.plog.serving.controller"))
				.paths(PathSelectors.any())
				.build()
				.apiInfo(apiInfo);
	}
}

